package com.emser.unc.server.domain;

import javax.jdo.annotations.Extension;
import javax.jdo.annotations.IdGeneratorStrategy;
import javax.jdo.annotations.IdentityType;
import javax.jdo.annotations.PersistenceCapable;
import javax.jdo.annotations.Persistent;
import javax.jdo.annotations.PrimaryKey;
import javax.jdo.annotations.Sequence;
import javax.jdo.annotations.SequenceStrategy;

import com.emser.unc.serializable.CustomerDTO;
import com.google.appengine.api.datastore.Key;

@PersistenceCapable(identityType = IdentityType.APPLICATION, detachable = "true")
@Sequence(name = "seqc", strategy = SequenceStrategy.NONTRANSACTIONAL,extensions = @Extension(vendorName = "datanucleus", key="key-cache-size", value="12"))
public class Customer {
	@PrimaryKey
	@Persistent(valueStrategy=IdGeneratorStrategy.IDENTITY)
	private Key key;
	@Persistent
	private Long id;
	@Persistent
	private String firstName;
	@Persistent
	private String lastName;
	@Persistent
	private String address;
	@Persistent
	private String city;
	@Persistent
	private String zipCode;
	@Persistent
	private String telephone;
	@Persistent
	private UserAccount userA;
	
	
	public Key getKey() {
		return key;
	}
	
	public String getFirstName() {
		return firstName;
	}
	public void setFirstName(String firstName) {
		this.firstName = firstName;
	}
	public String getLastName() {
		return lastName;
	}
	public void setLastName(String lastName) {
		this.lastName = lastName;
	}
	public String getAddress() {
		return address;
	}
	public void setAddress(String address) {
		this.address = address;
	}
	public String getTelephone() {
		return telephone;
	}
	public void setTelephone(String telephone) {
		this.telephone = telephone;
	}
	@Override
	public String toString() {
		return "Customer [id = " + id + ", firstName = " + firstName + ", lastName = " + lastName + 
		"address = " + address+ "telephone = " + telephone+ "]";
	}
	public static CustomerDTO toDTO(Customer customer) {
	    if (customer == null) {
	      return null;
	    }
	    CustomerDTO customerDTO = new CustomerDTO();
	    customerDTO.setCode(customer.getId());
	    customerDTO.setFirstName(customer.getFirstName());
	    customerDTO.setLastName(customer.getLastName());
	    customerDTO.setAddress(customer.getAddress());
	    customerDTO.setCity(customer.getCity());
	    customerDTO.setZipCode(customer.getZipCode());
	    customerDTO.setTelephone(customer.getTelephone());
	    return customerDTO;
	  }
	
	public UserAccount getUserA() {
		return userA;
	}
	
	public Long getId() {
		return id;
	}
	
	public void setId() {
		 id = key.getId();
	}

	public void setCity(String city) {
		this.city = city;
	}

	public String getCity() {
		return city;
	}

	public String getZipCode() {
		return zipCode;
	}
	public void setZipCode(String zipCode) {
		this.zipCode = zipCode;
	}

	
}
